package com.example.dellpc.myapplication;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.io.File;
import java.util.List;

/**
 * Created by 刘智强 on 2016/8/22.
 */
public class PhotoAdapter extends BaseAdapter {

    private Context context;
    private List<String> photos;

    public PhotoAdapter(Context context, List<String> photos) {
        this.context = context;
        this.photos = photos;
    }

    @Override
    public int getCount() {
        return photos.size();
    }

    @Override
    public Object getItem(int position) {
        return photos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VH vh=null;
        if (convertView==null){
            vh=new VH();
            convertView= LayoutInflater.from(context).inflate(R.layout.photoadapteritem,parent,false);
            vh.imageView= (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(vh);
        }else {
            vh= (VH) convertView.getTag();
        }
        Uri uri = Uri.fromFile(new File(photos.get(position)));
        Glide.with(context)
                .load(uri)
                .centerCrop()
                .thumbnail(0.1f)
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher)
                .into(vh.imageView);
        return convertView;
    }

    public class VH  {
        private ImageView imageView;



    }


//    @Override
//    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View itemView= LayoutInflater.from(context).inflate(R.layout.photoadapteritem,parent,false);
//
//        return new PhotoViewHolder(itemView);
//    }
//
//    @Override
//    public void onBindViewHolder(PhotoViewHolder holder, int position) {
//        Uri uri = Uri.fromFile(new File(photos.get(position)));
//        Log.d("111111111",photos.get(position));
//        Glide.with(context)
//                .load(uri)
//                .centerCrop()
//                .thumbnail(0.1f)
//                .placeholder(R.mipmap.ic_launcher)
//                .error(R.mipmap.ic_launcher)
//                .into(holder.imageView);
//
//
//    }
//
//    @Override
//    public int getItemCount() {
//        return photos.size();
//    }
//
//    public static  class PhotoViewHolder extends RecyclerView.ViewHolder{
//        private ImageView imageView;
//
//        public PhotoViewHolder(View itemView) {
//            super(itemView);
//            imageView= (ImageView) itemView.findViewById(R.id.image);
//        }
//    }
}
